home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / ejfract.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  67 lines

  1. ; $Id: ejfract.pro,v 1.4 1997/01/15 04:21:02 ali Exp $
  2. ;
  3. ; Copyright (c) 1988-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ; Demo file to determine ejection fraction of file abnorm.dat.
  7. ; Assumes abnorm.dat is in images subdirectory.
  8. ;
  9. ; Color table common:
  10. common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr
  11.  
  12. ;    Make a new window?
  13. if !d.window lt 0 and ((!d.flags and 256) ne 0) then window,title="Cardiac Demonstration"
  14. ;    Load orange color table if none loaded yet.
  15. if n_elements(r_orig) eq 0 then loadct,3  ;Load red color table if none
  16.                 ;have been loaded.
  17. top = !d.n_colors-1        ;Max display value
  18. xsize = 192            ;Size of movie display
  19. close,1                ;Be sure unit 1 is closed
  20. ;;;;    read,1,'Filename: ',filename
  21. openr,1,filepath('abnorm.dat', subdirectory=['examples','data'])    ;Open data file
  22. b = fstat(1)        ;Get size
  23. nframes = b.size / 4096    ;# of frames
  24. aa=assoc(1,bytarr(64,64)) ;64 x 64 images.
  25. erase
  26. diastole = fix(aa[0])    ;Diastolic image is first frame, use 16 bits
  27. tv,rebin(bytscl(diastole, top = top),256,256)    ;Blow up for display, show it
  28. print,'Mark ventricular region:'
  29. vent = defroi(64,64,zoom=4)    ;Get region of interest subscript array
  30. print,'Mark background region:'
  31. bkg = defroi(64,64,zoom=4)    ;Background region subscripts
  32. c=bytscl(diastole,top=top)    ;Copy for display...
  33. c[vent] = 255            ;Show regions by filling ROI's with 0's & 255.
  34. c[bkg] = 0
  35. tvcrs                ;No more cursor
  36. erase
  37. tv,rebin(c,xsize,xsize)        ;Show it blown up
  38.  
  39. c = fltarr(nframes-1)            ;Counts
  40. svmax = max(smooth(diastole - aa[7],3))    ;Scaling for sv
  41.  
  42. for i=0,nframes-2 do begin    ;Get time / activity curve.
  43.     a = aa[i]        ;Read image
  44.     if i le 19 then begin    ;show 1st 16
  45.      tvscl,a,i        ;Show image
  46.      tv,bytscl(smooth(diastole-a,3),$
  47.         min=0,max=svmax,top=top),i+20    ;Stroke volume
  48.      endif
  49.                 ;Counts = ventricle less background
  50.     c[i] = total(a[vent]) - total(a[bkg])*n_elements(vent)/n_elements(bkg)
  51.     endfor
  52.  
  53. plot,/noerase,title='Ejection Fraction',xtitle='Frame', $ 
  54.     pos = [.6,.12,.95,.46], $
  55.     ytitle='Ejection Fraction', 1-c/max(c) ;Plot and scale to eject fract
  56. ans = ""            ;Define a string for response
  57. read,"Do you want a movie (Y, N)? ",ans
  58. if strupcase(ans) eq "Y" then begin    ;Make a movie
  59.     b = bytarr(xsize,xsize,nframes-1,/noz)    ;memory for each frame
  60.     for i=0,nframes-2 do $
  61.       b[0,0,i] = rebin(reverse(bytscl(aa[i],top=top),2),xsize, xsize)
  62.     movie,b            ;show it
  63.     endif
  64.  
  65. close,1
  66. end
  67.